#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=100000, maxs=1000000000;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class SegmentTree {
public:
  int al, ar, v;
  SegmentTree *left, *right;

  SegmentTree(int l, int r) {
    al = l, ar = r;
  }

  void add(int t, int tv) {
    if (al==ar) {
      v += tv;
    } else {
      int mid=(al+ar)/2;
      if (t<=mid) {
	if (!left) {
	  left = new SegmentTree(al, mid);
	}
	left->add(t, tv);
      } else {
	if (!right) {
	  right = new SegmentTree(mid+1, ar);
	}
	right->add(t, tv);
      }
      v = (left ? left->v : 0)+(right ? right->v : 0);
    }
  }

  int get(int tl, int tr) {
    if (al==tl && ar==tr) {
      return v;
    } else {
      int mid=(al+ar)/2, ret=0;
      if (tl<=mid && tr>=al && left) {
	ret += left->get(max(tl, al), min(tr, mid));
      }
      if (tl<=ar && tr>mid && right) {
	ret += right->get(max(mid+1, tl), min(ar, tr));
      }
      return ret;
    }
  }
};

long long initF(int n, int s[], int f[]) {
  long long ret=0;
  SegmentTree *l = new SegmentTree(0, maxs);
  for (int i=1; i<=n; i++) {
    f[i] += l->get(s[i]+1, maxs);
    l->add(s[i], 1);
    ret += f[i];
  }
  SegmentTree *r = new SegmentTree(0, maxs);
  for (int i=n; i>0; i--) {
    f[i] += r->get(0, s[i]-1);
    r->add(s[i], 1);
  }
  return ret;
}

int main() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);

  static int s[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", s+i);
  }

  static int f[maxn+1];
  long long all = initF(n, s, f), ans=0;

  SegmentTree *l = new SegmentTree(0, maxs);
  for (int i=1; i<=n; i++) {
    int t=l->get(0, s[i]-1);
    l->add(s[i], 1);
    ans += (long long)all*t-(long long)f[i]*t;
  }
  SegmentTree *r = new SegmentTree(0, maxs);
  for (int i=n; i>0; i--) {
    int t=r->get(s[i]+1, maxs);
    r->add(s[i], 1);
    ans -= (long long)f[i]*t;
  }

  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
